import { defineConfig } from 'cypress'
import { beforeRunHook, afterRunHook } from 'cypress-mochawesome-reporter/lib'

export default defineConfig({
  e2e: {
    baseUrl: 'https://console.authing.cn',
    reporter: 'cypress-mochawesome-reporter',
    reporterOptions: {
      reportFilename: 'AuthingTestingReport',
      reportDir: 'cypress/results/report',
      overwrite: false,
      timestamp: 'yyyy_mm_dd_HH_MM_ss',
      showHooks: 'always',
      charts: true,
      embeddedScreenshots: true,
      inlineAssets: true,
      saveAllAttempts: false,
    },
    videosFolder: 'cypress/results/videos',
    screenshotsFolder: 'cypress/results/screenshots',
    defaultCommandTimeout: 15000,
    pageLoadTimeout: 15000,
    requestTimeout: 10000,
    viewportHeight: 1280,
    viewportWidth: 1920,
    setupNodeEvents(on) {
      require('cypress-mochawesome-reporter/plugin')(on)

      on('before:run', async (details) => {
        console.log('override before:run')
        await beforeRunHook(details)
      })

      on('after:run', async () => {
        console.log('override after:run')
        await afterRunHook()
      })
    },
  },
})
